﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Modeling.Diagrams;
using System.Drawing;
using Microsoft.VisualStudio.Modeling;

namespace UofCASE.AgileProductLinerDSL {

    public partial class TestShape {

         public void SetBackgroundColor(KnownColor color) {
            BrushSettings backgroundBrush = new BrushSettings();
            backgroundBrush.Color = global::System.Drawing.Color.FromKnownColor(color);
            this.StyleSet.OverrideBrush(DiagramBrushes.ShapeBackground, backgroundBrush);
            this.Invalidate(true);
        }

        public void GrayOut() {
            BrushSettings backgroundBrush = new BrushSettings();
            backgroundBrush.Color = global::System.Drawing.Color.Gainsboro;
            this.StyleSet.OverrideBrush(DiagramBrushes.ShapeBackground, backgroundBrush);
            BrushSettings forgroundBrush = new BrushSettings();
            forgroundBrush.ForeColor = global::System.Drawing.Color.LightGray;
            this.StyleSet.OverrideBrush(DiagramBrushes.ShapeText, forgroundBrush);
            PenSettings penSettings = new PenSettings();
            penSettings.Color = global::System.Drawing.Color.LightGray;
            this.StyleSet.OverridePen(DiagramPens.ShapeOutline, penSettings);
            this.Invalidate(true);
        }

        public void ResetColor() {
            this.UpdateBackgroundColor();
        }

        private void UpdateBackgroundColor() {
            Test test = this.ModelElement as Test;

            if (test == null) return;
            this.StyleSet.ClearBrushOverride(DiagramBrushes.ShapeBackground);
            this.StyleSet.ClearBrushOverride(DiagramBrushes.ShapeText);
            this.StyleSet.ClearPenOverride(DiagramPens.ShapeOutline);
            
            if (!test.IsMapped) {
                this.SetBackgroundColor(TestColor.Unmapped);
            } else {
                switch (test.LastTestRun) {
                    case TestResult.Successful: this.SetBackgroundColor(TestColor.Success); break;
                    case TestResult.None: this.SetBackgroundColor(TestColor.NoTestResult); break;
                    default: this.SetBackgroundColor(TestColor.Fail); break;
                }
            }
        }
    }
}
